﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.QcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.QcManagement.QcInspectRecordVMs
{
    public partial class QcInspectRecordListVM : BasePagedListVM<QcInspectRecord_View, QcInspectRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<QcInspectRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<QcInspectRecord_View>>{
                
                this.MakeGridHeader(x => x.QcInspectRecord_Sheet).SetTitle(@Localizer["Page.检验单"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_QcType).SetTitle(@Localizer["Page.检验分类"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_InspectName).SetTitle(@Localizer["Page.检验项目"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_InspectTool).SetTitle(@Localizer["Page.检测工具"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_Content).SetTitle(@Localizer["Page.检验内容"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_RefValue).SetTitle(@Localizer["Page.参考值"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_QcValue).SetTitle(@Localizer["Page.检验值"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_QcResult).SetTitle(@Localizer["Page.检验结果"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_OpCode).SetTitle(@Localizer["Page.责任工位"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.QcInspectRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<QcInspectRecord_View> GetSearchQuery()
        {
            var query = DC.Set<QcInspectRecord>()
                
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.QcType, x=>x.QcType)
                .CheckContain(Searcher.InspectName, x=>x.InspectName)
                .CheckContain(Searcher.InspectTool, x=>x.InspectTool)
                .CheckContain(Searcher.Content, x=>x.Content)
                .CheckContain(Searcher.RefValue, x=>x.RefValue)
                .CheckContain(Searcher.QcValue, x=>x.QcValue)
                .CheckEqual(Searcher.QcResult, x=>x.QcResult)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new QcInspectRecord_View
                {
				    ID = x.ID,
                    
                    QcInspectRecord_Sheet = x.Sheet.TenantCode,
                    QcInspectRecord_ProductId = x.ProductId,
                    QcInspectRecord_ProductName = x.ProductName,
                    QcInspectRecord_QcType = x.QcType,
                    QcInspectRecord_InspectName = x.InspectName,
                    QcInspectRecord_InspectTool = x.InspectTool,
                    QcInspectRecord_Content = x.Content,
                    QcInspectRecord_RefValue = x.RefValue,
                    QcInspectRecord_QcValue = x.QcValue,
                    QcInspectRecord_QcResult = x.QcResult,
                    QcInspectRecord_Remark = x.Remark,
                    QcInspectRecord_OpCode = x.OpCode,
                    QcInspectRecord_Sn = x.Sn,
                    QcInspectRecord_CreateTime = x.CreateTime,
                    QcInspectRecord_UpdateTime = x.UpdateTime,
                    QcInspectRecord_CreateBy = x.CreateBy,
                    QcInspectRecord_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class QcInspectRecord_View: QcInspectRecord
    {
        
        public string QcInspectRecord_Sheet { get; set; }
        public long? QcInspectRecord_ProductId { get; set; }
        public string QcInspectRecord_ProductName { get; set; }
        public EquipTypeEnum? QcInspectRecord_QcType { get; set; }
        public string QcInspectRecord_InspectName { get; set; }
        public string QcInspectRecord_InspectTool { get; set; }
        public string QcInspectRecord_Content { get; set; }
        public string QcInspectRecord_RefValue { get; set; }
        public string QcInspectRecord_QcValue { get; set; }
        public QcStatusEnum? QcInspectRecord_QcResult { get; set; }
        public string QcInspectRecord_Remark { get; set; }
        public string QcInspectRecord_OpCode { get; set; }
        public string QcInspectRecord_Sn { get; set; }
        public DateTime? QcInspectRecord_CreateTime { get; set; }
        public DateTime? QcInspectRecord_UpdateTime { get; set; }
        public string QcInspectRecord_CreateBy { get; set; }
        public string QcInspectRecord_UpdateBy { get; set; }

    }

}